package com.reremouse.rerebbs.web.mb;

import com.reremouse.rerebbs.dao.IBbsUserDAO;
import com.reremouse.rerebbs.model.BBSScoreRegular;
import com.reremouse.rerebbs.model.BbsUser;
import com.reremouse.util.JsfHelper;
import com.reremouse.util.SpringHelper;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import java.io.Serializable;
import java.util.Date;

@ManagedBean
@ViewScoped
public class BbsLogin
        implements Serializable {
    IBbsUserDAO bbsUserDAO = (IBbsUserDAO) SpringHelper.getSpringBean("BbsUserDAO");
    @ManagedProperty("#{clientSession}")
    ClientSession cs;
    String urn;
    String pwd;

    public ClientSession getCs() {
        return this.cs;
    }

    public void setCs(ClientSession cs) {
        this.cs = cs;
    }

    public String getUrn() {
        return this.urn;
    }

    public void setUrn(String urn) {
        this.urn = urn;
    }

    public String getPwd() {
        return this.pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String checkUserWithoutRedirecting() {
        System.out.println(this.urn + "try to login");
        FacesContext fc = FacesContext.getCurrentInstance();
        FacesMessage fm = new FacesMessage();
        fm.setSeverity(FacesMessage.SEVERITY_ERROR);
        BbsUser us = this.bbsUserDAO.findBbsUserByUrn(this.urn);
        if (us == null) {
            fm.setSummary("无此用户");
            fc.addMessage("", fm);
            return null;
        }
        String pwd_real = us.getPassword();
        if (!this.pwd.equals(pwd_real)) {
            fm.setSummary("password error");
            fc.addMessage("", fm);
            return null;
        }
        if (!us.getEnabled().booleanValue()) {
            fm.setSummary("此用户已被禁用！");
            fc.addMessage("", fm);
            return null;
        }
        if (!us.getActivated().booleanValue()) {
            fm.setSummary("此用户尚未激活！");
            fc.addMessage("", fm);
            return null;
        }
        this.cs.setUsr(us);
        this.cs.setIfLogin(true);
        us.setLastIp(JsfHelper.getRequest().getRemoteAddr());
        us.setLastTime(new Date());
        us.setScore(us.getScore() + BBSScoreRegular.LOGIN);
        this.bbsUserDAO.updateBbsUser(us);
        this.urn = "";
        this.pwd = "";
        return null;
/* :0:   */
    }

    /* :1:   */
/* :2:   */
    public String checkUser()
/* :3:   */ {
/* :4:97 */
        checkUserWithoutRedirecting();
/* :5:98 */
        return "zoneList";
/* :6:   */
    }
/* :7:   */
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.web.mb.BbsLogin

 * JD-Core Version:    0.7.0.1

 */